Importing necessary libraries

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(zoo)
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(xts)
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
library(quantmod)
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(imputeTS)
## 
## Attaching package: 'imputeTS'
## 
## The following object is masked from 'package:zoo':
## 
##     na.locf
library(tseries)
## Warning: package 'tseries' was built under R version 4.3.3
## 
## Attaching package: 'tseries'
## 
## The following object is masked from 'package:imputeTS':
## 
##     na.remove
library(rugarch)
## Loading required package: parallel
## 
## Attaching package: 'rugarch'
## 
## The following object is masked from 'package:purrr':
## 
##     reduce
## 
## The following object is masked from 'package:stats':
## 
##     sigma
library(FinTS)
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following object is masked from 'package:purrr':
## 
##     some
library(fBasics)
## 
## Attaching package: 'fBasics'
## 
## The following object is masked from 'package:car':
## 
##     densityPlot
## 
## The following objects are masked from 'package:rugarch':
## 
##     qgh, qnig
## 
## The following object is masked from 'package:TTR':
## 
##     volatility

Lets load additional function defined which will be used to to easily compare information criteria for ARCH and GARCH models.

source("/Users/elgun/Desktop/ESTIMATING-VALUE-AT-RISK-OF-A-PORTFOLIO-WITH-GARCH-FAMILY-MODELS-Time-Series-project/functions/compare_ICs_ugarchfit.R")

Import the data

# Fetch data for Dow Jones
Dow_Jones <- getSymbols("^DJI", src = "yahoo", from = "2019-01-01", to = "2024-06-01", auto.assign = FALSE)
# Rename the column
colnames(Dow_Jones) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")

# Fetch data for TSMC
Tmsc <- getSymbols("TSM", src = "yahoo", from = "2019-01-01", to = "2024-06-01", auto.assign = FALSE)
# Rename the column
colnames(Tmsc) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")

# Fetch data for Pound
Pound <- getSymbols("GBPUSD=X", src = "yahoo", from = "2019-01-01", to = "2024-06-01", auto.assign = FALSE)
## Warning: GBPUSD=X contains missing values. Some functions will not work if
## objects contain missing values in the middle of the series. Consider using
## na.omit(), na.approx(), na.fill(), etc to remove or replace them.
# Rename the column
colnames(Pound) <- c("Open", "High", "Low", "Close", "Volume","Adjusted")

# Fetch data for Silver
Silver <- getSymbols("SI=F", src = "yahoo", from = "2019-01-01", to = "2024-06-01", auto.assign = FALSE)
## Warning: SI=F contains missing values. Some functions will not work if objects
## contain missing values in the middle of the series. Consider using na.omit(),
## na.approx(), na.fill(), etc to remove or replace them.
# Rename the column
colnames(Silver) <- c("Open", "High", "Low", "Close",  "Volume","Adjusted")

# Fetch data for BNB
BNB <- getSymbols("BNB-USD", src = "yahoo", from = "2019-01-01", to = "2024-06-01", auto.assign = FALSE)
# Rename the column
colnames(BNB) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")

print(Pound)
##                Open     High      Low    Close Volume Adjusted
## 2019-01-01 1.275022 1.275673 1.271456 1.273804      0 1.273804
## 2019-01-02 1.275234 1.277335 1.258463 1.275429      0 1.275429
## 2019-01-03 1.251878 1.263823 1.251878 1.252191      0 1.252191
## 2019-01-04 1.262897 1.273966 1.261782 1.262881      0 1.262881
## 2019-01-07 1.273285 1.278772 1.272426 1.273496      0 1.273496
## 2019-01-08 1.278691 1.279230 1.271488 1.278609      0 1.278609
## 2019-01-09 1.273885 1.280295 1.271779 1.273788      0 1.273788
## 2019-01-10 1.279951 1.280115 1.273058 1.279967      0 1.279967
## 2019-01-11 1.275836 1.283746 1.271666 1.275396      0 1.275396
## 2019-01-14 1.284984 1.292775 1.282101 1.284984      0 1.284984
##        ...                                                    
## 2024-05-19 1.270793 1.271294 1.269148 1.270648      0 1.270648
## 2024-05-20 1.271052 1.272734 1.269293 1.271084      0 1.271084
## 2024-05-21 1.271036 1.276129 1.270099 1.271133      0 1.271133
## 2024-05-22 1.272087 1.274697 1.270616 1.272103      0 1.272103
## 2024-05-23 1.269374 1.275136 1.268279 1.269406      0 1.269406
## 2024-05-26 1.273447 1.277900 1.273447 1.273610      0 1.273610
## 2024-05-27 1.277270 1.279984 1.276308 1.277237      0 1.277237
## 2024-05-28 1.276000 1.277172 1.270713 1.275836      0 1.275836
## 2024-05-29 1.269825 1.274762 1.268183 1.269799      0 1.269799
## 2024-05-30 1.273026 1.276552 1.270164 1.273042      0 1.273042

Handling with NA values use na_locf

Dow_Jones$Adjusted <- na_locf(Dow_Jones$Adjusted)
Tmsc$Adjusted <- na_locf(Tmsc$Adjusted)
Pound$Adjusted <- na_locf(Pound$Adjusted)
Silver$Adjusted <- na_locf(Silver$Adjusted)
BNB$Adjusted <- na_locf(BNB$Adjusted)

Log return of ecah asset

Dow_Jones$r <- diff.xts(log(Dow_Jones$Adjusted))
Tmsc$r <- diff.xts(log(Tmsc$Adjusted))
Pound$r <- diff.xts(log(Pound$Adjusted))
Silver$r <- diff.xts(log(Silver$Adjusted))
BNB$r <- diff.xts(log(BNB$Adjusted))
print(Dow_Jones$r)
##                        r
## 2019-01-02            NA
## 2019-01-03 -0.0286782307
## 2019-01-04  0.0323943972
## 2019-01-07  0.0041814381
## 2019-01-08  0.0108245398
## 2019-01-09  0.0038463031
## 2019-01-10  0.0051294230
## 2019-01-11 -0.0002487903
## 2019-01-14 -0.0035949504
## 2019-01-15  0.0064929297
##        ...              
## 2024-05-17  0.0033606129
## 2024-05-20 -0.0049322096
## 2024-05-21  0.0016621227
## 2024-05-22 -0.0050776824
## 2024-05-23 -0.0153878018
## 2024-05-24  0.0001107860
## 2024-05-28 -0.0055627365
## 2024-05-29 -0.0106430531
## 2024-05-30 -0.0086230600
## 2024-05-31  0.0149704959

Portfolio construction

# Calculate the combined returns of all assets
combined_returns <- Dow_Jones$r + Tmsc$r + Pound$r + Silver$r + BNB$r
# Calculate the portfolio returns with equal weights
weight <- 0.2
portfolio_returns <- combined_returns * weight
# Convert the xts object to a data frame
portfolio_df1 <- data.frame(date = index(combined_returns), portfolio_returns = coredata(portfolio_returns))
portfolio_df1 <- na.omit(portfolio_df1)
# Ensure the date column is in Date format
portfolio_df1$date <- as.Date(portfolio_df1$date)
# Removing observations after `2023-01-01`
portfolio_df <- portfolio_df1 %>%
  filter(date <= as.Date("2023-01-01"))

# Print the portfolio data frame
print(na.omit(portfolio_df))
##           date             r
## 1   2019-01-03 -2.893906e-02
## 2   2019-01-04  1.695959e-02
## 3   2019-01-07  3.633670e-04
## 4   2019-01-08  1.155042e-02
## 5   2019-01-09  4.202983e-03
## 6   2019-01-10 -1.782659e-02
## 7   2019-01-11  5.799201e-03
## 8   2019-01-14  1.664867e-02
## 9   2019-01-15 -5.516295e-03
## 10  2019-01-16  7.951595e-03
## 11  2019-01-17  1.127519e-02
## 12  2019-01-18  9.962925e-03
## 13  2019-01-22 -6.272823e-03
## 14  2019-01-23  4.393590e-03
## 15  2019-01-24  5.808924e-03
## 16  2019-01-25  1.692400e-02
## 17  2019-01-28 -2.976633e-02
## 18  2019-01-29 -6.144328e-03
## 19  2019-01-30  8.947376e-03
## 20  2019-01-31  6.518470e-03
## 21  2019-02-01  7.521108e-03
## 22  2019-02-04  1.279901e-02
## 23  2019-02-05  2.098143e-02
## 24  2019-02-06  6.237640e-03
## 25  2019-02-07 -1.408381e-02
## 26  2019-02-08  1.998576e-02
## 27  2019-02-11  7.791279e-03
## 28  2019-02-12 -7.631099e-04
## 29  2019-02-13 -1.052835e-02
## 30  2019-02-14 -6.913862e-03
## 31  2019-02-15  1.646065e-02
## 32  2019-02-19  2.351583e-02
## 33  2019-02-20  1.549272e-02
## 34  2019-02-21 -1.455611e-02
## 35  2019-02-22  1.136427e-02
## 36  2019-02-25 -4.685734e-03
## 37  2019-02-26 -5.813537e-03
## 38  2019-02-27  6.474030e-03
## 39  2019-02-28  5.818520e-03
## 40  2019-03-01  1.588692e-02
## 41  2019-03-04 -5.070624e-03
## 42  2019-03-05  3.418675e-02
## 43  2019-03-06  7.194552e-03
## 44  2019-03-07  5.889336e-03
## 45  2019-03-08 -1.021734e-02
## 46  2019-03-11  1.555752e-03
## 47  2019-03-12  1.832809e-02
## 48  2019-03-13 -3.272777e-03
## 49  2019-03-14 -3.144793e-03
## 50  2019-03-15  7.248347e-03
## 51  2019-03-18  1.058984e-03
## 52  2019-03-19 -3.502687e-04
## 53  2019-03-20 -6.614074e-03
## 54  2019-03-21 -2.016285e-03
## 55  2019-03-22  2.029385e-03
## 56  2019-03-25 -4.406069e-03
## 57  2019-03-26 -4.231081e-03
## 58  2019-03-27  2.357061e-03
## 59  2019-03-28 -3.412043e-03
## 60  2019-03-29  1.528920e-03
## 61  2019-04-01  1.131738e-02
## 62  2019-04-02  1.887757e-02
## 63  2019-04-03 -6.664786e-03
## 64  2019-04-04  4.809799e-03
## 65  2019-04-08 -8.484493e-03
## 66  2019-04-09  1.054823e-03
## 67  2019-04-10 -1.481866e-04
## 68  2019-04-11 -1.317009e-02
## 69  2019-04-15 -3.260510e-04
## 70  2019-04-16  5.089476e-03
## 71  2019-04-17  4.314918e-03
## 72  2019-04-18  2.827193e-02
## 73  2019-04-22 -3.767837e-03
## 74  2019-04-23 -9.682067e-03
## 75  2019-04-24  2.879247e-03
## 76  2019-04-25 -1.360175e-02
## 77  2019-04-29 -1.305925e-02
## 78  2019-04-30  6.509837e-03
## 79  2019-05-01 -6.057688e-03
## 80  2019-05-02  1.435203e-02
## 81  2019-05-06 -1.344589e-02
## 82  2019-05-07 -1.651040e-02
## 83  2019-05-08 -3.117322e-03
## 84  2019-05-09 -2.379460e-02
## 85  2019-05-13  1.223967e-02
## 86  2019-05-14  4.452366e-03
## 87  2019-05-15  2.590403e-02
## 88  2019-05-16 -9.231522e-03
## 89  2019-05-20 -8.636498e-03
## 90  2019-05-21  2.195424e-02
## 91  2019-05-22 -6.971081e-03
## 92  2019-05-23 -3.694023e-03
## 93  2019-05-28 -1.035335e-02
## 94  2019-05-29  1.535909e-03
## 95  2019-05-30 -5.702157e-03
## 96  2019-06-03 -5.811931e-03
## 97  2019-06-04 -6.920793e-03
## 98  2019-06-05  8.180831e-03
## 99  2019-06-06  7.236262e-03
## 100 2019-06-10  8.551050e-03
## 101 2019-06-11  4.732878e-03
## 102 2019-06-12  1.136288e-02
## 103 2019-06-13  5.151633e-03
## 104 2019-06-17  7.927220e-03
## 105 2019-06-18  1.585100e-02
## 106 2019-06-19  7.661781e-03
## 107 2019-06-20  2.312270e-02
## 108 2019-06-24  6.446731e-03
## 109 2019-06-25 -1.625985e-02
## 110 2019-06-26 -9.772764e-04
## 111 2019-06-27 -9.626354e-03
## 112 2019-07-01  1.207003e-02
## 113 2019-07-02 -8.030656e-03
## 114 2019-07-03  4.130861e-03
## 115 2019-07-08 -1.994229e-03
## 116 2019-07-09 -2.651119e-03
## 117 2019-07-10 -8.046320e-05
## 118 2019-07-11 -1.020849e-02
## 119 2019-07-15  1.694744e-04
## 120 2019-07-16 -1.939709e-02
## 121 2019-07-17  1.542218e-02
## 122 2019-07-18  2.407141e-02
## 123 2019-07-22  6.506926e-03
## 124 2019-07-23 -6.260699e-03
## 125 2019-07-24 -3.492652e-04
## 126 2019-07-25 -9.367616e-03
## 127 2019-07-29 -4.246989e-03
## 128 2019-07-30 -5.284241e-03
## 129 2019-07-31 -1.506188e-03
## 130 2019-08-01 -9.536789e-04
## 131 2019-08-05 -9.724153e-03
## 132 2019-08-06  7.499753e-03
## 133 2019-08-07  2.039390e-02
## 134 2019-08-08  1.275238e-02
## 135 2019-08-12 -1.838250e-03
## 136 2019-08-13  1.273601e-03
## 137 2019-08-14 -2.633414e-02
## 138 2019-08-15  9.464088e-03
## 139 2019-08-19  6.626180e-03
## 140 2019-08-20 -2.118154e-03
## 141 2019-08-21 -4.101940e-03
## 142 2019-08-22 -3.789306e-04
## 143 2019-08-26  5.765798e-03
## 144 2019-08-27  2.634171e-03
## 145 2019-08-28 -1.189902e-02
## 146 2019-08-29 -1.245175e-02
## 147 2019-09-03  1.272590e-03
## 148 2019-09-04  7.914733e-03
## 149 2019-09-05  9.953095e-03
## 150 2019-09-09  5.596410e-05
## 151 2019-09-10 -1.320791e-03
## 152 2019-09-11 -7.664518e-03
## 153 2019-09-12 -1.010487e-04
## 154 2019-09-16  5.260560e-04
## 155 2019-09-17  1.094663e-02
## 156 2019-09-18  8.447021e-03
## 157 2019-09-19 -4.791854e-03
## 158 2019-09-23 -4.896087e-04
## 159 2019-09-24 -3.947283e-02
## 160 2019-09-25 -5.552603e-04
## 161 2019-09-26 -6.570187e-03
## 162 2019-09-30  4.447331e-03
## 163 2019-10-01  4.574434e-03
## 164 2019-10-02 -1.734897e-03
## 165 2019-10-03  1.646436e-03
## 166 2019-10-07  9.779524e-03
## 167 2019-10-08 -2.378806e-03
## 168 2019-10-09  2.598051e-02
## 169 2019-10-10  7.160978e-04
## 170 2019-10-14  5.248677e-03
## 171 2019-10-15  3.214801e-03
## 172 2019-10-16 -7.466878e-03
## 173 2019-10-17  9.497002e-03
## 174 2019-10-21  3.267328e-03
## 175 2019-10-22 -1.318810e-03
## 176 2019-10-23 -1.703173e-02
## 177 2019-10-24  6.251656e-03
## 178 2019-10-28  5.273167e-03
## 179 2019-10-29  7.516817e-03
## 180 2019-10-30 -6.567869e-04
## 181 2019-10-31 -2.176023e-04
## 182 2019-11-01  4.714981e-03
## 183 2019-11-04  1.138042e-02
## 184 2019-11-05 -6.001775e-03
## 185 2019-11-06  1.542113e-03
## 186 2019-11-07 -7.399441e-03
## 187 2019-11-08 -1.600594e-02
## 188 2019-11-11 -4.225935e-03
## 189 2019-11-12  5.300780e-03
## 190 2019-11-13  9.712771e-03
## 191 2019-11-14 -1.390547e-05
## 192 2019-11-15 -4.971677e-03
## 193 2019-11-18 -7.606118e-03
## 194 2019-11-19 -4.074658e-03
## 195 2019-11-20 -7.905398e-03
## 196 2019-11-21 -1.819640e-02
## 197 2019-11-22 -1.634214e-02
## 198 2019-11-25  2.479120e-03
## 199 2019-11-26  5.840579e-03
## 200 2019-11-27  6.536496e-03
## 201 2019-11-29  4.004058e-03
## 202 2019-12-02 -7.879997e-03
## 203 2019-12-03  2.592757e-03
## 204 2019-12-04 -7.967667e-04
## 205 2019-12-05  1.441912e-02
## 206 2019-12-06 -1.057403e-03
## 207 2019-12-09 -5.082574e-03
## 208 2019-12-10 -5.554242e-03
## 209 2019-12-11  4.962400e-03
## 210 2019-12-12  1.320571e-02
## 211 2019-12-13  4.527733e-03
## 212 2019-12-16 -1.214210e-02
## 213 2019-12-17 -1.720997e-02
## 214 2019-12-18  1.452170e-02
## 215 2019-12-19 -2.154230e-03
## 216 2019-12-20  2.045815e-03
## 217 2019-12-23 -2.188552e-03
## 218 2019-12-24  2.383302e-03
## 219 2019-12-26  5.076572e-03
## 220 2019-12-27  3.144052e-03
## 221 2019-12-30 -4.229710e-03
## 222 2019-12-31 -2.352225e-03
## 223 2020-01-02  3.128700e-04
## 224 2020-01-03  8.157040e-04
## 225 2020-01-06  9.025661e-03
## 226 2020-01-07  6.841894e-03
## 227 2020-01-08 -6.255549e-03
## 228 2020-01-09 -1.010368e-03
## 229 2020-01-10  6.366652e-03
## 230 2020-01-13  1.805774e-03
## 231 2020-01-14  1.495282e-02
## 232 2020-01-15  9.453718e-03
## 233 2020-01-16 -3.842222e-03
## 234 2020-01-17  1.390247e-02
## 235 2020-01-21  3.895070e-03
## 236 2020-01-22 -2.479582e-03
## 237 2020-01-23 -1.061115e-02
## 238 2020-01-24  2.793822e-03
## 239 2020-01-27 -1.054442e-02
## 240 2020-01-28  5.773712e-03
## 241 2020-01-29 -2.028126e-03
## 242 2020-01-30  9.224589e-03
## 243 2020-01-31 -1.388176e-02
## 244 2020-02-03  1.908631e-03
## 245 2020-02-04  5.445864e-03
## 246 2020-02-05  1.682502e-02
## 247 2020-02-06  1.676693e-02
## 248 2020-02-07  3.059988e-03
## 249 2020-02-10  1.189085e-02
## 250 2020-02-11  7.282715e-03
## 251 2020-02-12  1.102649e-02
## 252 2020-02-13 -8.383569e-03
## 253 2020-02-14  5.249024e-03
## 254 2020-02-18  6.310865e-05
## 255 2020-02-19 -7.291082e-03
## 256 2020-02-20 -6.832490e-03
## 257 2020-02-21 -3.533511e-03
## 258 2020-02-24 -1.479921e-02
## 259 2020-02-25 -3.123710e-02
## 260 2020-02-26 -1.517891e-02
## 261 2020-02-27 -1.543477e-02
## 262 2020-02-28 -1.877770e-02
## 263 2020-03-02  2.876556e-02
## 264 2020-03-03 -7.036568e-03
## 265 2020-03-04  2.148551e-02
## 266 2020-03-05 -1.165652e-03
## 267 2020-03-06 -4.327602e-05
## 268 2020-03-09 -3.335604e-02
## 269 2020-03-10  2.179749e-02
## 270 2020-03-11 -2.943056e-02
## 271 2020-03-12 -1.545601e-01
## 272 2020-03-13  3.238666e-02
## 273 2020-03-16 -1.066352e-01
## 274 2020-03-17  3.296689e-02
## 275 2020-03-18 -4.466514e-02
## 276 2020-03-19  3.801449e-02
## 277 2020-03-20 -1.123935e-02
## 278 2020-03-23  2.951798e-02
## 279 2020-03-24  5.566293e-02
## 280 2020-03-25  1.574721e-02
## 281 2020-03-26  2.820290e-02
## 282 2020-03-27 -2.745447e-02
## 283 2020-03-30  1.713831e-02
## 284 2020-03-31  1.841674e-03
## 285 2020-04-01 -1.486727e-02
## 286 2020-04-02  2.592484e-02
## 287 2020-04-06  5.512183e-02
## 288 2020-04-07 -9.771622e-04
## 289 2020-04-08  1.128807e-02
## 290 2020-04-09  6.528657e-03
## 291 2020-04-13  2.357795e-03
## 292 2020-04-14  2.786005e-02
## 293 2020-04-15 -2.960126e-02
## 294 2020-04-16  2.664958e-02
## 295 2020-04-20 -1.917301e-02
## 296 2020-04-21 -2.056957e-02
## 297 2020-04-22  2.281232e-02
## 298 2020-04-23  4.498034e-03
## 299 2020-04-27  7.106306e-03
## 300 2020-04-28 -3.625349e-03
## 301 2020-04-29  2.370755e-02
## 302 2020-04-30 -1.442905e-02
## 303 2020-05-04  1.943285e-03
## 304 2020-05-05  1.775485e-03
## 305 2020-05-06 -6.197199e-03
## 306 2020-05-07  1.511947e-02
## 307 2020-05-11 -8.127571e-03
## 308 2020-05-12 -1.114986e-03
## 309 2020-05-13 -6.355682e-04
## 310 2020-05-14  1.632249e-02
## 311 2020-05-18  2.633279e-02
## 312 2020-05-19  4.563924e-03
## 313 2020-05-20  4.821572e-03
## 314 2020-05-21 -2.213064e-02
## 315 2020-05-26  7.085515e-03
## 316 2020-05-27  1.163132e-02
## 317 2020-05-28  3.136620e-03
## 318 2020-06-01  1.925991e-02
## 319 2020-06-02 -6.356853e-03
## 320 2020-06-03  8.305149e-03
## 321 2020-06-04  6.555644e-03
## 322 2020-06-08  9.056430e-03
## 323 2020-06-09  5.742331e-04
## 324 2020-06-10  9.389673e-04
## 325 2020-06-11 -3.735630e-02
## 326 2020-06-15 -8.882940e-04
## 327 2020-06-16  5.770172e-03
## 328 2020-06-17  2.207639e-03
## 329 2020-06-18 -7.800139e-03
## 330 2020-06-22  1.258783e-02
## 331 2020-06-23  5.258585e-03
## 332 2020-06-24 -1.721779e-02
## 333 2020-06-25  5.391769e-03
## 334 2020-06-29  4.909800e-03
## 335 2020-06-30  9.266021e-03
## 336 2020-07-01  1.661395e-03
## 337 2020-07-02  4.490175e-03
## 338 2020-07-06  2.778293e-02
## 339 2020-07-07  9.594477e-04
## 340 2020-07-08  1.877500e-02
## 341 2020-07-09 -2.162427e-03
## 342 2020-07-13  1.205770e-02
## 343 2020-07-14  4.013235e-03
## 344 2020-07-15 -3.782419e-03
## 345 2020-07-16 -6.984468e-03
## 346 2020-07-20  2.067284e-03
## 347 2020-07-21  2.083276e-02
## 348 2020-07-22  2.177124e-02
## 349 2020-07-23 -9.102698e-04
## 350 2020-07-27  4.128580e-02
## 351 2020-07-28 -1.300392e-02
## 352 2020-07-29  1.398406e-02
## 353 2020-07-30 -1.320572e-02
## 354 2020-08-03  1.356401e-02
## 355 2020-08-04  1.938626e-02
## 356 2020-08-05  2.272552e-02
## 357 2020-08-06  4.262645e-03
## 358 2020-08-10  1.589262e-02
## 359 2020-08-11 -4.169152e-02
## 360 2020-08-12  9.696815e-03
## 361 2020-08-13  1.293454e-02
## 362 2020-08-17  1.575177e-02
## 363 2020-08-18 -1.106397e-03
## 364 2020-08-19 -1.696494e-02
## 365 2020-08-20  3.021044e-03
## 366 2020-08-24  9.483821e-03
## 367 2020-08-25 -9.111726e-03
## 368 2020-08-26  2.194010e-02
## 369 2020-08-27  1.988947e-03
## 370 2020-08-31 -2.385393e-03
## 371 2020-09-01  2.167540e-02
## 372 2020-09-02 -5.997619e-03
## 373 2020-09-03 -4.923299e-02
## 374 2020-09-08 -2.434350e-03
## 375 2020-09-09  2.086503e-02
## 376 2020-09-10 -5.370014e-03
## 377 2020-09-14  1.164846e-02
## 378 2020-09-15 -1.299748e-02
## 379 2020-09-16  5.803658e-04
## 380 2020-09-17 -1.241454e-02
## 381 2020-09-21 -5.105444e-02
## 382 2020-09-22  7.770007e-03
## 383 2020-09-23 -3.340579e-02
## 384 2020-09-24  1.790146e-02
## 385 2020-09-28  1.716575e-02
## 386 2020-09-29  2.125510e-02
## 387 2020-09-30 -2.808575e-04
## 388 2020-10-01 -3.173907e-03
## 389 2020-10-05  1.574049e-02
## 390 2020-10-06 -1.969556e-02
## 391 2020-10-07  1.300337e-02
## 392 2020-10-08  3.140676e-03
## 393 2020-10-12  2.283567e-02
## 394 2020-10-13 -1.521823e-02
## 395 2020-10-14  1.323136e-03
## 396 2020-10-15 -1.800982e-03
## 397 2020-10-19 -3.095603e-03
## 398 2020-10-20 -2.903918e-03
## 399 2020-10-21  9.316785e-03
## 400 2020-10-22  3.150204e-03
## 401 2020-10-26 -3.823276e-03
## 402 2020-10-27  2.056436e-03
## 403 2020-10-28 -3.172856e-02
## 404 2020-10-29 -4.663832e-04
## 405 2020-10-30 -1.127565e-02
## 406 2020-11-02  6.597125e-03
## 407 2020-11-03  3.575428e-03
## 408 2020-11-04  6.560619e-03
## 409 2020-11-05  1.978110e-02
## 410 2020-11-06  1.753944e-02
## 411 2020-11-09 -1.679002e-02
## 412 2020-11-10  6.100537e-03
## 413 2020-11-11  5.155435e-03
## 414 2020-11-12 -7.217886e-03
## 415 2020-11-13  1.649608e-02
## 416 2020-11-16  2.064616e-02
## 417 2020-11-17 -6.324386e-03
## 418 2020-11-18 -4.095586e-03
## 419 2020-11-19 -3.570524e-03
## 420 2020-11-20  3.932867e-03
## 421 2020-11-23  9.656522e-03
## 422 2020-11-24  1.505738e-02
## 423 2020-11-25 -1.346019e-02
## 424 2020-11-27 -2.750772e-03
## 425 2020-11-30  2.446334e-03
## 426 2020-12-01  1.360942e-02
## 427 2020-12-02  2.333904e-04
## 428 2020-12-03  2.902965e-03
## 429 2020-12-04  1.271286e-03
## 430 2020-12-07  6.812704e-03
## 431 2020-12-08 -1.430610e-02
## 432 2020-12-09 -5.566014e-03
## 433 2020-12-10 -3.067086e-03
## 434 2020-12-11 -3.417421e-03
## 435 2020-12-14  3.935164e-03
## 436 2020-12-15  7.042710e-03
## 437 2020-12-16  1.115306e-02
## 438 2020-12-17  6.921768e-03
## 439 2020-12-18  4.677215e-03
## 440 2020-12-21 -1.006347e-02
## 441 2020-12-22 -1.477237e-03
## 442 2020-12-23 -1.206851e-02
## 443 2020-12-24  1.497628e-02
## 444 2020-12-28  2.041233e-02
## 445 2020-12-29  1.104503e-02
## 446 2020-12-30  5.642600e-03
## 447 2020-12-31 -1.732944e-03
## 448 2021-01-04  8.486232e-03
## 449 2021-01-05  7.365013e-03
## 450 2021-01-06  6.358056e-03
## 451 2021-01-07  1.880259e-02
## 452 2021-01-08 -3.016997e-02
## 453 2021-01-11 -9.801569e-03
## 454 2021-01-12  9.416376e-04
## 455 2021-01-13  7.294145e-03
## 456 2021-01-14  2.086057e-02
## 457 2021-01-15 -1.409910e-02
## 458 2021-01-19  2.275159e-03
## 459 2021-01-20  4.309304e-03
## 460 2021-01-21 -1.323943e-02
## 461 2021-01-22  9.204859e-04
## 462 2021-01-25 -4.917502e-04
## 463 2021-01-26 -5.381258e-03
## 464 2021-01-27 -1.572356e-02
## 465 2021-01-28  1.903339e-02
## 466 2021-01-29 -1.235770e-03
## 467 2021-02-01  5.781641e-02
## 468 2021-02-02 -1.814339e-02
## 469 2021-02-03  6.785495e-03
## 470 2021-02-04  1.170680e-02
## 471 2021-02-05  4.499972e-02
## 472 2021-02-08  4.418966e-02
## 473 2021-02-09  5.922408e-02
## 474 2021-02-10  3.745826e-02
## 475 2021-02-11 -3.969662e-04
## 476 2021-02-12  1.949848e-02
## 477 2021-02-16  4.617101e-03
## 478 2021-02-17  4.187416e-02
## 479 2021-02-18  2.952860e-02
## 480 2021-02-19  1.115844e-01
## 481 2021-02-22 -1.631566e-02
## 482 2021-02-23 -3.833806e-02
## 483 2021-02-24  2.876982e-02
## 484 2021-02-25 -3.126505e-02
## 485 2021-02-26 -2.496213e-02
## 486 2021-03-01  4.914958e-02
## 487 2021-03-02 -1.715432e-02
## 488 2021-03-03 -7.809037e-03
## 489 2021-03-04 -3.147102e-02
## 490 2021-03-05  7.482630e-03
## 491 2021-03-08 -1.037711e-02
## 492 2021-03-09  5.103703e-02
## 493 2021-03-10 -1.077430e-02
## 494 2021-03-11  2.106787e-02
## 495 2021-03-12 -2.223191e-02
## 496 2021-03-15 -3.310445e-03
## 497 2021-03-16 -2.127924e-04
## 498 2021-03-17  1.029396e-02
## 499 2021-03-18 -1.108881e-02
## 500 2021-03-19 -2.115461e-03
## 501 2021-03-22 -5.686343e-03
## 502 2021-03-23 -9.819209e-03
## 503 2021-03-24 -1.714454e-02
## 504 2021-03-25 -1.044242e-02
## 505 2021-03-26  3.148129e-02
## 506 2021-03-29 -1.738464e-03
## 507 2021-03-30  1.974017e-02
## 508 2021-03-31  2.712520e-03
## 509 2021-04-01  3.668379e-02
## 510 2021-04-05  1.055098e-02
## 511 2021-04-06  1.707211e-02
## 512 2021-04-07 -2.009250e-02
## 513 2021-04-08  3.058200e-02
## 514 2021-04-12  1.964257e-02
## 515 2021-04-13 -1.234626e-02
## 516 2021-04-14  6.629965e-04
## 517 2021-04-15 -1.393957e-03
## 518 2021-04-19  3.623380e-03
## 519 2021-04-20  2.701817e-02
## 520 2021-04-21 -2.931946e-03
## 521 2021-04-22 -2.497191e-02
## 522 2021-04-26  1.723324e-02
## 523 2021-04-27  1.354421e-02
## 524 2021-04-28 -7.467202e-03
## 525 2021-04-29  1.296804e-02
## 526 2021-05-03  2.602275e-02
## 527 2021-05-04 -2.419391e-02
## 528 2021-05-05  1.345680e-02
## 529 2021-05-06  5.871668e-03
## 530 2021-05-10 -1.623911e-02
## 531 2021-05-11  1.218251e-02
## 532 2021-05-12 -4.331931e-02
## 533 2021-05-13 -3.777238e-03
## 534 2021-05-17 -1.686007e-02
## 535 2021-05-18 -2.857562e-04
## 536 2021-05-19 -8.239423e-02
## 537 2021-05-20  3.396220e-02
## 538 2021-05-24  6.192007e-02
## 539 2021-05-25  8.727695e-04
## 540 2021-05-26  2.110268e-02
## 541 2021-05-27 -4.390784e-03
## 542 2021-06-01  6.597619e-03
## 543 2021-06-02  2.198362e-02
## 544 2021-06-03  2.967306e-03
## 545 2021-06-07 -2.130969e-02
## 546 2021-06-08 -8.395872e-03
## 547 2021-06-09  1.451649e-02
## 548 2021-06-10 -9.917499e-03
## 549 2021-06-14  4.353879e-03
## 550 2021-06-15 -3.420319e-03
## 551 2021-06-16 -1.912036e-02
## 552 2021-06-17 -1.069405e-02
## 553 2021-06-21 -4.279167e-02
## 554 2021-06-22 -7.081212e-03
## 555 2021-06-23  2.833787e-02
## 556 2021-06-24  1.197154e-02
## 557 2021-06-28  4.438497e-03
## 558 2021-06-29  5.148566e-03
## 559 2021-06-30  5.205916e-03
## 560 2021-07-01 -1.405618e-02
## 561 2021-07-06  9.399801e-03
## 562 2021-07-07  1.242342e-03
## 563 2021-07-08 -1.411682e-02
## 564 2021-07-12  4.175826e-04
## 565 2021-07-13 -5.312391e-03
## 566 2021-07-14  3.182322e-03
## 567 2021-07-15 -6.728796e-03
## 568 2021-07-19 -2.682126e-02
## 569 2021-07-20 -7.891997e-03
## 570 2021-07-21  2.735380e-02
## 571 2021-07-22  5.427045e-04
## 572 2021-07-26  1.499828e-03
## 573 2021-07-27 -2.804935e-03
## 574 2021-07-28  3.994822e-03
## 575 2021-07-29  1.285452e-02
## 576 2021-08-02 -1.436962e-03
## 577 2021-08-03 -4.535433e-04
## 578 2021-08-04  4.771896e-03
## 579 2021-08-05  3.320222e-03
## 580 2021-08-09 -2.354950e-03
## 581 2021-08-10  7.961482e-03
## 582 2021-08-11  1.225683e-02
## 583 2021-08-12 -7.440303e-03
## 584 2021-08-16  2.851015e-04
## 585 2021-08-17 -1.802294e-02
## 586 2021-08-18 -7.153245e-03
## 587 2021-08-19  1.224763e-02
## 588 2021-08-23  3.396863e-02
## 589 2021-08-24 -7.379725e-03
## 590 2021-08-25  2.121832e-02
## 591 2021-08-26 -1.179578e-02
## 592 2021-08-30 -9.194962e-03
## 593 2021-08-31  1.843448e-03
## 594 2021-09-01  1.496933e-02
## 595 2021-09-02 -2.805180e-03
## 596 2021-09-07 -3.912865e-02
## 597 2021-09-08 -8.942855e-03
## 598 2021-09-09  5.417582e-03
## 599 2021-09-13 -6.974635e-03
## 600 2021-09-14  5.265986e-03
## 601 2021-09-15  6.756617e-03
## 602 2021-09-16 -1.329237e-02
## 603 2021-09-20 -3.517378e-02
## 604 2021-09-21 -6.127047e-03
## 605 2021-09-22  2.487710e-02
## 606 2021-09-23  5.329162e-03
## 607 2021-09-27 -5.430412e-04
## 608 2021-09-28 -1.699019e-02
## 609 2021-09-29  9.421230e-03
## 610 2021-09-30  1.276788e-02
## 611 2021-10-04 -7.228468e-03
## 612 2021-10-05  1.005468e-02
## 613 2021-10-06 -3.782608e-03
## 614 2021-10-07  7.729188e-03
## 615 2021-10-11  2.327661e-03
## 616 2021-10-12  1.008472e-02
## 617 2021-10-13  2.027472e-02
## 618 2021-10-14  1.089412e-02
## 619 2021-10-18  5.596294e-03
## 620 2021-10-19  1.124315e-02
## 621 2021-10-20  8.791925e-03
## 622 2021-10-21 -1.379328e-02
## 623 2021-10-25  3.849536e-03
## 624 2021-10-26 -5.685219e-03
## 625 2021-10-27 -1.440405e-02
## 626 2021-10-28  2.396480e-02
## 627 2021-11-01  1.054764e-02
## 628 2021-11-02 -3.242136e-03
## 629 2021-11-03  2.536194e-03
## 630 2021-11-04  1.011066e-02
## 631 2021-11-05  1.720472e-02
## 632 2021-11-08  9.874761e-03
## 633 2021-11-09 -5.867375e-03
## 634 2021-11-10 -1.003025e-02
## 635 2021-11-11  5.878728e-03
## 636 2021-11-12  4.530923e-04
## 637 2021-11-15 -7.725166e-03
## 638 2021-11-16 -1.534084e-02
## 639 2021-11-17 -1.514967e-03
## 640 2021-11-18 -1.084843e-02
## 641 2021-11-19  1.675926e-02
## 642 2021-11-22 -1.316722e-02
## 643 2021-11-23 -9.586090e-04
## 644 2021-11-24 -4.356467e-03
## 645 2021-11-26 -2.104955e-02
## 646 2021-11-29  6.966209e-03
## 647 2021-11-30 -8.564965e-03
## 648 2021-12-01  4.306235e-04
## 649 2021-12-02  2.228835e-03
## 650 2021-12-03 -1.068473e-02
## 651 2021-12-06  1.147894e-02
## 652 2021-12-07  7.495964e-03
## 653 2021-12-08  7.607633e-03
## 654 2021-12-09 -2.030496e-02
## 655 2021-12-10 -4.162125e-03
## 656 2021-12-13 -2.298095e-02
## 657 2021-12-14 -8.922295e-03
## 658 2021-12-15  1.718475e-02
## 659 2021-12-16 -2.235468e-03
## 660 2021-12-17 -2.247585e-03
## 661 2021-12-20 -1.093165e-02
## 662 2021-12-21  1.133110e-02
## 663 2021-12-22  1.325392e-02
## 664 2021-12-23  8.099766e-03
## 665 2021-12-27  1.129192e-02
## 666 2021-12-28 -8.903579e-03
## 667 2021-12-29 -1.098191e-02
## 668 2021-12-30  2.309034e-03
## 669 2021-12-31 -7.240831e-04
## 670 2022-01-03  3.295130e-03
## 671 2022-01-04  7.958337e-03
## 672 2022-01-05 -2.341502e-02
## 673 2022-01-06 -7.741101e-03
## 674 2022-01-07 -1.733934e-02
## 675 2022-01-10 -3.564384e-03
## 676 2022-01-11  2.794825e-02
## 677 2022-01-12  1.898460e-02
## 678 2022-01-13  5.036726e-03
## 679 2022-01-14  5.066809e-03
## 680 2022-01-18 -9.975524e-03
## 681 2022-01-19 -4.624654e-03
## 682 2022-01-20 -1.195459e-02
## 683 2022-01-21 -3.973287e-02
## 684 2022-01-24 -8.725299e-03
## 685 2022-01-25  8.819958e-04
## 686 2022-01-26 -4.870869e-03
## 687 2022-01-27 -1.414563e-02
## 688 2022-01-28 -1.168423e-03
## 689 2022-01-31  1.050296e-02
## 690 2022-02-01  1.000313e-02
## 691 2022-02-02 -4.316410e-03
## 692 2022-02-03 -1.054725e-02
## 693 2022-02-04  1.785377e-02
## 694 2022-02-07  1.286766e-02
## 695 2022-02-08 -6.143124e-03
## 696 2022-02-09  1.256325e-02
## 697 2022-02-10 -6.417853e-03
## 698 2022-02-11 -1.714271e-02
## 699 2022-02-14  3.648980e-03
## 700 2022-02-15  1.912855e-02
## 701 2022-02-16 -1.520426e-03
## 702 2022-02-17 -1.923301e-02
## 703 2022-02-18 -2.076045e-03
## 704 2022-02-22  5.429881e-03
## 705 2022-02-23 -6.816678e-03
## 706 2022-02-24 -8.999871e-03
## 707 2022-02-25  3.008763e-03
## 708 2022-02-28  1.286873e-02
## 709 2022-03-01  1.492392e-02
## 710 2022-03-02  2.591707e-03
## 711 2022-03-03 -4.152652e-03
## 712 2022-03-04 -1.876832e-02
## 713 2022-03-07 -1.537064e-02
## 714 2022-03-08  8.032094e-03
## 715 2022-03-09  1.081800e-02
## 716 2022-03-10 -9.010929e-03
## 717 2022-03-11 -8.332248e-03
## 718 2022-03-14 -5.404295e-03
## 719 2022-03-15  6.608756e-03
## 720 2022-03-16  1.519887e-02
## 721 2022-03-17  1.590695e-02
## 722 2022-03-18  1.079226e-03
## 723 2022-03-21  3.905321e-03
## 724 2022-03-22  2.569531e-03
## 725 2022-03-23  9.708301e-05
## 726 2022-03-24  1.433138e-02
## 727 2022-03-25 -5.468939e-03
## 728 2022-03-28 -4.668434e-03
## 729 2022-03-29  5.410219e-03
## 730 2022-03-30  2.486259e-03
## 731 2022-03-31 -1.388506e-02
## 732 2022-04-04  2.884136e-03
## 733 2022-04-05 -8.111719e-03
## 734 2022-04-06 -1.567828e-02
## 735 2022-04-07  9.187107e-03
## 736 2022-04-11 -1.679812e-02
## 737 2022-04-12  1.457973e-02
## 738 2022-04-13  1.867280e-02
## 739 2022-04-14 -1.430441e-02
## 740 2022-04-18  7.996669e-03
## 741 2022-04-19  1.082268e-03
## 742 2022-04-20 -1.491051e-03
## 743 2022-04-21 -1.718392e-02
## 744 2022-04-25 -1.156397e-03
## 745 2022-04-26 -2.524371e-02
## 746 2022-04-27 -3.430342e-03
## 747 2022-04-28  1.793776e-02
## 748 2022-05-02 -3.583165e-03
## 749 2022-05-03 -2.360043e-03
## 750 2022-05-04  1.978580e-02
## 751 2022-05-05 -3.038686e-02
## 752 2022-05-09 -5.274881e-02
## 753 2022-05-10  1.173302e-02
## 754 2022-05-11 -3.760143e-02
## 755 2022-05-12 -9.342258e-03
## 756 2022-05-16 -4.165324e-03
## 757 2022-05-17  1.890332e-02
## 758 2022-05-18 -2.994246e-02
## 759 2022-05-19  1.605021e-02
## 760 2022-05-23  5.217470e-03
## 761 2022-05-24  3.935830e-03
## 762 2022-05-25  2.307512e-03
## 763 2022-05-26 -7.448659e-03
## 764 2022-05-31 -3.245514e-03
## 765 2022-06-01 -1.497179e-02
## 766 2022-06-02  1.584341e-02
## 767 2022-06-06 -1.523901e-03
## 768 2022-06-07  1.495335e-03
## 769 2022-06-08 -5.128958e-03
## 770 2022-06-09 -1.198235e-02
## 771 2022-06-13 -4.926194e-02
## 772 2022-06-14 -1.592440e-03
## 773 2022-06-15  2.238474e-02
## 774 2022-06-16 -2.878958e-02
## 775 2022-06-21  1.304741e-02
## 776 2022-06-22 -1.335989e-02
## 777 2022-06-23  9.292173e-03
## 778 2022-06-27 -5.502174e-04
## 779 2022-06-28 -1.728528e-02
## 780 2022-06-29 -1.016152e-02
## 781 2022-06-30 -9.515992e-03
## 782 2022-07-05 -1.217776e-02
## 783 2022-07-06  5.435152e-03
## 784 2022-07-07  1.993624e-02
## 785 2022-07-11 -1.765179e-02
## 786 2022-07-12 -8.258522e-03
## 787 2022-07-13  1.531388e-02
## 788 2022-07-14  5.635317e-04
## 789 2022-07-18  1.067603e-02
## 790 2022-07-19  1.343173e-02
## 791 2022-07-20 -7.564650e-03
## 792 2022-07-21  1.019851e-02
## 793 2022-07-25 -1.469257e-02
## 794 2022-07-26 -9.591014e-04
## 795 2022-07-27  3.032817e-02
## 796 2022-07-28  2.194918e-02
## 797 2022-08-01 -2.217445e-03
## 798 2022-08-02 -6.842366e-03
## 799 2022-08-03  1.112988e-02
## 800 2022-08-04  1.463117e-02
## 801 2022-08-08  5.288491e-03
## 802 2022-08-09 -8.072380e-03
## 803 2022-08-10  1.818949e-02
## 804 2022-08-11 -4.889635e-03
## 805 2022-08-15 -1.695455e-03
## 806 2022-08-16 -5.501227e-03
## 807 2022-08-17 -1.340526e-02
## 808 2022-08-18 -9.913651e-03
## 809 2022-08-22 -1.221929e-02
## 810 2022-08-23  2.482007e-03
## 811 2022-08-24 -4.395936e-03
## 812 2022-08-25  1.284487e-02
## 813 2022-08-29 -7.214819e-05
## 814 2022-08-30 -1.084154e-02
## 815 2022-08-31 -7.458912e-03
## 816 2022-09-01 -7.056688e-03
## 817 2022-09-06 -1.440190e-02
## 818 2022-09-07  1.841843e-02
## 819 2022-09-08  5.391081e-03
## 820 2022-09-12  1.455110e-02
## 821 2022-09-13 -3.450432e-02
## 822 2022-09-14  5.145130e-03
## 823 2022-09-15 -1.515782e-02
## 824 2022-09-19  6.361820e-03
## 825 2022-09-20 -9.350892e-03
## 826 2022-09-21 -6.214923e-03
## 827 2022-09-22  4.817024e-03
## 828 2022-09-26 -8.351628e-03
## 829 2022-09-27 -5.847934e-03
## 830 2022-09-28  1.585357e-02
## 831 2022-09-29 -5.670249e-03
## 832 2022-10-03  2.833022e-02
## 833 2022-10-04  2.894550e-02
## 834 2022-10-05 -4.268315e-03
## 835 2022-10-06 -1.012693e-02
## 836 2022-10-10 -1.839002e-02
## 837 2022-10-11 -1.556318e-02
## 838 2022-10-12 -1.656515e-03
## 839 2022-10-13  1.724759e-02
## 840 2022-10-17  1.800982e-02
## 841 2022-10-18 -4.395119e-03
## 842 2022-10-19 -6.628747e-03
## 843 2022-10-20  9.053478e-04
## 844 2022-10-24 -5.963001e-03
## 845 2022-10-25  1.355693e-02
## 846 2022-10-26  7.667620e-03
## 847 2022-10-27 -2.135221e-03
## 848 2022-10-31  5.889987e-03
## 849 2022-11-01  1.948747e-03
## 850 2022-11-02 -9.712056e-03
## 851 2022-11-03  6.608405e-04
## 852 2022-11-04  3.379665e-02
## 853 2022-11-07  5.975885e-03
## 854 2022-11-08  1.221613e-02
## 855 2022-11-09 -4.614741e-02
## 856 2022-11-10  5.089026e-02
## 857 2022-11-11  4.248730e-03
## 858 2022-11-14  3.216197e-03
## 859 2022-11-15  1.288259e-02
## 860 2022-11-16 -4.039468e-03
## 861 2022-11-17 -2.674990e-03
## 862 2022-11-18  6.823952e-03
## 863 2022-11-21 -1.458182e-02
## 864 2022-11-22  1.889270e-02
## 865 2022-11-23  2.572649e-02
## 866 2022-11-25  8.929453e-04
## 867 2022-11-28 -2.344045e-02
## 868 2022-11-29  2.853585e-03
## 869 2022-11-30  1.987077e-02
## 870 2022-12-01  4.239908e-03
## 871 2022-12-02  4.859472e-03
## 872 2022-12-05 -1.195771e-02
## 873 2022-12-06 -8.288218e-03
## 874 2022-12-07 -7.619792e-04
## 875 2022-12-08  1.372941e-02
## 876 2022-12-09 -7.331250e-04
## 877 2022-12-12 -5.943724e-03
## 878 2022-12-13  3.110392e-03
## 879 2022-12-14 -2.203204e-03
## 880 2022-12-15 -2.304064e-02
## 881 2022-12-16 -3.077239e-02
## 882 2022-12-19 -1.158869e-02
## 883 2022-12-20  1.723182e-02
## 884 2022-12-21  2.682055e-03
## 885 2022-12-22 -1.365992e-02
## 886 2022-12-23  2.053295e-03
## 887 2022-12-27  3.362720e-03
## 888 2022-12-28 -1.173805e-02
## 889 2022-12-29  1.538127e-02
## 890 2022-12-30 -6.366028e-03

Log-returns plot

plot(portfolio_df$r, 
     col = "red",
     major.ticks = "years", 
     grid.ticks.on = "years",
     main = "Log-returns of Portfolio")
## Warning in plot.window(...): "major.ticks" is not a graphical parameter
## Warning in plot.window(...): "grid.ticks.on" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.ticks" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "grid.ticks.on" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.ticks" is
## not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "grid.ticks.on" is
## not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.ticks" is
## not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "grid.ticks.on" is
## not a graphical parameter
## Warning in box(...): "major.ticks" is not a graphical parameter
## Warning in box(...): "grid.ticks.on" is not a graphical parameter
## Warning in title(...): "major.ticks" is not a graphical parameter
## Warning in title(...): "grid.ticks.on" is not a graphical parameter

Plot of ACF for returns

acf(portfolio_df$r,lag.max = 36, na.action = na.pass,col="darkblue",lwd=7,main="ACF of Portfolio returns")

acf(portfolio_df$r, lag.max = 36, na.action = na.pass, ylim = c(-0.2, 0.2),
    col = "darkblue", lwd = 7, main = "ACF of Portfolio returns")

Plot of ACF for squared returns.

acf(portfolio_df$r^2,lag.max = 100,na.action = na.pass,col="darkblue",lwd=7,main="ACF of Portfolio squared returns")

acf(portfolio_df$r^2,lag.max = 100,na.action = na.pass,
    ylim= c(0, 0.5),col="darkblue",lwd=7,main="CF of Portfolio squared returns")

Lag 1,2,3,4,6,8 seems significant. ## Normality test

basicStats((portfolio_df$r))
##             X..portfolio_df.r
## nobs               890.000000
## NAs                  0.000000
## Minimum             -0.154560
## Maximum              0.111584
## 1. Quartile         -0.007075
## 3. Quartile          0.009494
## Mean                 0.001027
## Median               0.001057
## Sum                  0.913659
## SE Mean              0.000567
## LCL Mean            -0.000086
## UCL Mean             0.002139
## Variance             0.000286
## Stdev                0.016908
## Skewness            -0.897962
## Kurtosis            12.613657

Skewness is negative and we also observe strong excess kurtosis.

tibble(r = as.numeric(portfolio_df$r)) %>%
  ggplot(aes(r)) +
  geom_histogram(aes(y =..density..),
                 colour = "black", 
                 fill = "pink") +
  stat_function(fun = dnorm, 
                args = list(mean = mean(portfolio_df$r), 
                            sd = sd(portfolio_df$r))) +
  theme_bw() + 
  labs(
    title = "Density of the portfolio log-returns", 
    y = "", x = "",
    caption = "source: own calculations"
  )
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

As we can see, the distribution of the returns is highly leptokurtic.

jarque.bera.test(portfolio_df$r)
## 
##  Jarque Bera Test
## 
## data:  portfolio_df$r
## X-squared = 6053.1, df = 2, p-value < 2.2e-16

The null hypothesis about normality strongly rejected!

Testing for ARCH effects.

ArchTest(portfolio_df$r,lags = 5)
## 
##  ARCH LM-test; Null hypothesis: no ARCH effects
## 
## data:  portfolio_df$r
## Chi-squared = 117.13, df = 5, p-value < 2.2e-16

There is very strong evidence to reject the null-hypothesis that there are no ARCH effects in the data.

Standardization of returns.

portfolio_df$stan <-(portfolio_df$r-mean(portfolio_df$r, na.rm=T))/ sd(portfolio_df$r, na.rm = T)

tail(portfolio_df$stan)
## [1] -0.86859005  0.06072186  0.13816399 -0.75492673  0.84896594 -0.43721426

Histogram of standart return

hist(portfolio_df$stan, prob=T, breaks = 40)
curve(dnorm(x, mean(portfolio_df$stan, na.rm= T),
            sd=sd(portfolio_df$stan, na.rm = T)),
      col="darkblue",lwd=2, add=TRUE)

Descriptive statistics of standardized returns .

basicStats(portfolio_df$stan)
##             X..portfolio_df.stan
## nobs                  890.000000
## NAs                     0.000000
## Minimum                -9.201715
## Maximum                 6.538615
## 1. Quartile            -0.479149
## 3. Quartile             0.500763
## Mean                    0.000000
## Median                  0.001793
## Sum                     0.000000
## SE Mean                 0.033520
## LCL Mean               -0.065788
## UCL Mean                0.065788
## Variance                1.000000
## Stdev                   1.000000
## Skewness               -0.897962
## Kurtosis               12.613657

1% empirical quantile

quantile(portfolio_df$stan,0.01, na.rm=T)
##        1% 
## -2.631463

For comparison: 1% quantile of standard normal distribution

qnorm(0.01,0,1)
## [1] -2.326348

Build GARCH models

Estimating the GARCH(1,1)

Here, first we have to define a model specification:

spec <- ugarchspec(variance.model = list(model="sGARCH",garchOrder= c(1,1)),mean.model = list(armaOrder = c(0,0), include.mean= T),distribution.model = "norm")

Estimate the model:

portfolio_df.garch11 <- ugarchfit(spec = spec, 
                           data = portfolio_df$r)

Now, we can see the results:

portfolio_df.garch11
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000785    0.000451   1.7381 0.082189
## omega   0.000014    0.000003   5.5947 0.000000
## alpha1  0.146300    0.019368   7.5537 0.000000
## beta1   0.809070    0.017357  46.6137 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000785    0.000446   1.7576 0.078818
## omega   0.000014    0.000008   1.9153 0.055453
## alpha1  0.146300    0.027753   5.2716 0.000000
## beta1   0.809070    0.056667  14.2777 0.000000
## 
## LogLikelihood : 2473.557 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -5.5496
## Bayes        -5.5280
## Shibata      -5.5496
## Hannan-Quinn -5.5413
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.756  0.1852
## Lag[2*(p+q)+(p+q)-1][2]     1.943  0.2724
## Lag[4*(p+q)+(p+q)-1][5]     2.782  0.4483
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.2575  0.6118
## Lag[2*(p+q)+(p+q)-1][5]    1.2208  0.8080
## Lag[4*(p+q)+(p+q)-1][9]    1.9909  0.9061
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]    0.0198 0.500 2.000  0.8881
## ARCH Lag[5]    0.8020 1.440 1.667  0.7925
## ARCH Lag[7]    1.1231 2.315 1.543  0.8927
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  7.6581
## Individual Statistics:              
## mu     0.28254
## omega  0.89762
## alpha1 0.07765
## beta1  0.12538
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.07 1.24 1.6
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           1.2984 0.1945    
## Negative Sign Bias  0.1061 0.9155    
## Positive Sign Bias  0.1665 0.8678    
## Joint Effect        2.5933 0.4587    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     37.19    0.0075096
## 2    30     54.16    0.0031032
## 3    40     64.79    0.0058664
## 4    50     87.42    0.0006097
## 
## 
## Elapsed time : 0.03735805

Interpration of results

1.Ljung-Box Tests for Residuals and Squared Residuals: The Ljung-Box tests for both standardized residuals and squared standardized residuals indicate that there is no significant autocorrelation remaining in the residuals at the tested lags.

2.Arch Test for Residuals: No remaining ARCH effects, suggesting the model has adequately captured conditional heteroscedasticity.

3.Nyblom Stability Test: Indicates potential instability in the model parameters over time, particularly the constant term (ω).

4.Sign Bias Test: Shows no evidence of asymmetry in the impact of positive and negative shocks on volatility, suggesting the model handles these shocks symmetrically.

5.Adjusted Pearson Goodness-of-Fit Test: Reveals significant deviations from normality in the model’s residuals, indicating the model may not adequately capture the true distribution of the data.

Conditional SD (vs |returns|)

plot(portfolio_df.garch11, which=3)

There are periods where the volatility is relatively low and stable, suggesting less market turbulence.

ACF of Standardized Residuals

plot(portfolio_df.garch11, which=10)

ACF of Squared Standardized Residuals

plot(portfolio_df.garch11, which=11)

plot(portfolio_df.garch11, which=12)

Positive and negative shocks of equal magnitude have the same impact on volatility. The U-shaped curve indicates that both positive and negative shocks increase volatility, but the impact diminishes as the magnitude of the shock decreases.

The EGARCH model

Here, first we have to define a model specification:

spec <- ugarchspec(# variance equation
                   variance.model = list(model = "eGARCH", 
                                         garchOrder = c(1, 1)),
                   # sGARCH would stand for standard GARCH model
                   # mean equation
                   mean.model = list(armaOrder = c(0, 0), 
                                     include.mean = TRUE), 
                   # assumed distribution of errors
                   distribution.model = "norm")

Estimate the model:

portfolio_df.egarch11 <- ugarchfit(spec = spec, 
                           data = portfolio_df$r)

Now, we can see the results:

portfolio_df.egarch11
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : eGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.001059    0.000308  3.43698 0.000588
## omega  -0.375593    0.109973 -3.41531 0.000637
## alpha1 -0.010965    0.021057 -0.52075 0.602540
## beta1   0.953260    0.013109 72.71627 0.000000
## gamma1  0.264774    0.033653  7.86774 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.001059    0.000211  5.00693 0.000001
## omega  -0.375593    0.119341 -3.14722 0.001648
## alpha1 -0.010965    0.039602 -0.27689 0.781863
## beta1   0.953260    0.013766 69.24699 0.000000
## gamma1  0.264774    0.069090  3.83230 0.000127
## 
## LogLikelihood : 2473.587 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -5.5474
## Bayes        -5.5205
## Shibata      -5.5474
## Hannan-Quinn -5.5371
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.482  0.2234
## Lag[2*(p+q)+(p+q)-1][2]     1.872  0.2849
## Lag[4*(p+q)+(p+q)-1][5]     2.879  0.4295
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1083  0.7421
## Lag[2*(p+q)+(p+q)-1][5]    2.2163  0.5683
## Lag[4*(p+q)+(p+q)-1][9]    3.0676  0.7478
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]   0.04129 0.500 2.000  0.8390
## ARCH Lag[5]   0.76302 1.440 1.667  0.8043
## ARCH Lag[7]   0.99522 2.315 1.543  0.9143
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  0.7094
## Individual Statistics:              
## mu     0.33897
## omega  0.10151
## alpha1 0.07545
## beta1  0.10189
## gamma1 0.06438
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.28 1.47 1.88
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           1.5077 0.1320    
## Negative Sign Bias  0.1736 0.8623    
## Positive Sign Bias  0.5713 0.5680    
## Joint Effect        2.7772 0.4273    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     39.62     0.003672
## 2    30     45.46     0.026528
## 3    40     64.61     0.006114
## 4    50     78.99     0.004244
## 
## 
## Elapsed time : 0.04063892

Interpration

1.Ljung-Box Tests for Residuals and Squared Residuals: The Ljung-Box test results indicate no significant serial correlation, suggesting that the model is appropriate for capturing the autocorrelation in the time series data.Similarly, the test results for the squared residuals indicate no significant serial correlation, suggesting that the model adequately captures the conditional heteroscedasticity (volatility clustering).

2.Arch Test for Residuals: The fitted model adequately captures both autocorrelation and conditional heteroscedasticity in the time series data, indicating no significant serial correlation or ARCH effects in the residuals.

3.Nyblom Stability Test: The Nyblom stability test indicates that all parameters in the model are stable, with no significant evidence of instability in either individual or joint tests.

4.Sign Bias Test: Based on the Sign Bias Test results, there is no significant indication of a systematic bias in the signs of the residuals, suggesting that the model’s residuals exhibit no discernible pattern in their signs.

5.Adjusted Pearson Goodness-of-Fit Test: The Adjusted Pearson Goodness-of-Fit Test results suggest that the model does not adequately fit the observed data across all groups. The low p-values indicate significant evidence against the model’s fit, implying that the model may need adjustments or improvements to better capture the characteristics of the data.

Conditional SD (vs |returns|)

plot(portfolio_df.egarch11, which = 3)

There are periods where the volatility is relatively low and stable, suggesting less market turbulence.

ACF of Standardized Residuals

plot(portfolio_df.egarch11, which = 10)

ACF of Squared Standardized Residuals

plot(portfolio_df.egarch11, which = 11)

News-impact curve

plot(portfolio_df.egarch11, which = 12)

Positive and negative shocks of equal magnitude have the same impact on volatility. The U-shaped curve indicates that both positive and negative shocks increase volatility, but the impact diminishes as the magnitude of the shock decreases.

The GARCH-in-Mean model

Let’s first define a model specification:

spec <- ugarchspec(# variance equation
                   variance.model = list(model = "sGARCH", 
                                         # sGARCH = standard GARCH
                                         garchOrder = c(1, 1)),
                   # mean equation - lets turn on the intercept term
                   mean.model = list(armaOrder = c(0, 0), 
                                     include.mean = TRUE,
                       # we add an element to the mean equation,
                       # which can be either stdev (archpow 1)
                       # or var (archpow=2)
                                     archm = TRUE, archpow = 1), 
                   # assumed distribution of errors
                   distribution.model = "norm")

Then, we can estimate the model:

portfolio_df.garchm11 <- ugarchfit(spec = spec, 
                           data = portfolio_df$r)

Let’s examine the results:

portfolio_df.garchm11
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.001444    0.001847 -0.78193 0.434253
## archm   0.162857    0.130265  1.25020 0.211227
## omega   0.000015    0.000003  4.81129 0.000001
## alpha1  0.149075    0.019749  7.54855 0.000000
## beta1   0.805595    0.016655 48.37068 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.001444    0.001685 -0.85678  0.39157
## archm   0.162857    0.114424  1.42328  0.15465
## omega   0.000015    0.000010  1.53070  0.12584
## alpha1  0.149075    0.028109  5.30356  0.00000
## beta1   0.805595    0.066298 12.15106  0.00000
## 
## LogLikelihood : 2474.321 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -5.5490
## Bayes        -5.5221
## Shibata      -5.5491
## Hannan-Quinn -5.5387
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.885  0.1697
## Lag[2*(p+q)+(p+q)-1][2]     2.094  0.2477
## Lag[4*(p+q)+(p+q)-1][5]     2.899  0.4257
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.2724  0.6018
## Lag[2*(p+q)+(p+q)-1][5]    1.3477  0.7773
## Lag[4*(p+q)+(p+q)-1][9]    2.1878  0.8814
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]   0.02703 0.500 2.000  0.8694
## ARCH Lag[5]   0.86152 1.440 1.667  0.7744
## ARCH Lag[7]   1.25066 2.315 1.543  0.8697
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  7.2369
## Individual Statistics:              
## mu     0.36461
## archm  0.36412
## omega  0.85120
## alpha1 0.08096
## beta1  0.11809
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.28 1.47 1.88
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                     t-value   prob sig
## Sign Bias          0.910554 0.3628    
## Negative Sign Bias 0.035967 0.9713    
## Positive Sign Bias 0.009599 0.9923    
## Joint Effect       1.504741 0.6812    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     36.61     0.008883
## 2    30     51.73     0.005841
## 3    40     74.94     0.000472
## 4    50     84.94     0.001101
## 
## 
## Elapsed time : 0.131501

Interpration

1.Ljung-Box Tests for Residuals and Squared Residuals: Both the Weighted Ljung-Box tests on standardized residuals and standardized squared residuals suggest that there is no evidence of serial correlation in the residuals at the 5% significance level.

2.Arch Test for Residuals: These results suggest that there is no significant evidence of autoregressive conditional heteroskedasticity (ARCH effects) in the residuals of the model at the 5% significance level.

3.Nyblom Stability Test: he Nyblom stability test suggests that the model’s parameters are stable.

4.Sign Bias Test: the Sign Bias Test suggests that there’s no significant systematic bias in the signs of the residuals.

5.Adjusted Pearson Goodness-of-Fit Test: Reject the null hypothesis and conclude that there is a significant difference between the observed and expected frequencies in each group.

Conditional SD (vs |returns|)

plot(portfolio_df.garchm11, which = 3)

There are periods where the volatility is relatively low and stable, suggesting less market turbulence.

ACF of Standardized Residuals

plot(portfolio_df.garchm11, which = 10)

ACF of Squared Standardized Residuals

plot(portfolio_df.garchm11, which = 11)

News-impact curve

plot(portfolio_df.garchm11, which = 12)

Positive and negative shocks of equal magnitude have the same impact on volatility. The U-shaped curve indicates that both positive and negative shocks increase volatility, but the impact diminishes as the magnitude of the shock decreases.

The GARCH-t model

Let’s see whether conditional distribution of the error term can be better described by the t-Student distribution.

Let’s first define a model specification:

spec <- ugarchspec(# variance equation
                   variance.model = list(model = "sGARCH", 
                                         garchOrder = c(1, 1)),
                   # mean equation
                   mean.model = list(armaOrder = c(0, 0), 
                                     include.mean = TRUE), 
                   # assumed distribution of errors
                   distribution.model = "std") # std = t-Student

Then, we estimate the model:

portfolio_df.garcht11 <- ugarchfit(spec = spec, 
                           data = portfolio_df$r)

Model summary:

portfolio_df.garcht11
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : std 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.001061    0.000418   2.5398 0.011092
## omega   0.000014    0.000002   7.8966 0.000000
## alpha1  0.092405    0.000656 140.7937 0.000000
## beta1   0.851642    0.019658  43.3229 0.000000
## shape   4.885653    0.687331   7.1082 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.001061    0.000398   2.6667 0.007659
## omega   0.000014    0.000003   5.0925 0.000000
## alpha1  0.092405    0.013962   6.6183 0.000000
## beta1   0.851642    0.015344  55.5031 0.000000
## shape   4.885653    0.600187   8.1402 0.000000
## 
## LogLikelihood : 2522.343 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -5.6570
## Bayes        -5.6300
## Shibata      -5.6570
## Hannan-Quinn -5.6467
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.297  0.2548
## Lag[2*(p+q)+(p+q)-1][2]     1.624  0.3335
## Lag[4*(p+q)+(p+q)-1][5]     2.290  0.5517
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                   0.006618  0.9352
## Lag[2*(p+q)+(p+q)-1][5]  2.554874  0.4943
## Lag[4*(p+q)+(p+q)-1][9]  3.274714  0.7129
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]    0.1841 0.500 2.000  0.6679
## ARCH Lag[5]    0.5576 1.440 1.667  0.8665
## ARCH Lag[7]    0.6395 2.315 1.543  0.9641
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  21.6399
## Individual Statistics:             
## mu     0.3539
## omega  1.6842
## alpha1 0.2489
## beta1  0.4075
## shape  0.3869
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.28 1.47 1.88
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           1.3693 0.1713    
## Negative Sign Bias  0.4521 0.6513    
## Positive Sign Bias  0.8065 0.4201    
## Joint Effect        3.3422 0.3418    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     12.29       0.8728
## 2    30     19.10       0.9187
## 3    40     30.09       0.8463
## 4    50     53.71       0.2987
## 
## 
## Elapsed time : 0.06211805

Interpration

1.Ljung-Box Tests for Residuals and Squared Residuals: There is no evidence of significant serial correlation in the residuals of your time series model.

2.Arch Test for Residuals: There is no significant ARCH effect present in the residuals of your time series model at the conventional significance level.

3.Nyblom Stability Test: There is evidence of instability in the parameters of your time series model, particularly for “omega” and “beta1”.

4.Sign Bias Test: There is no evidence of systematic sign bias in the residuals of your time series model.

5.Adjusted Pearson Goodness-of-Fit Test: There isn’t significant evidence to suggest a lack of fit between the observed and expected frequencies in each group, based on the adjusted Pearson goodness-of-fit test.

Conditional SD (vs |returns|)

plot(portfolio_df.garcht11, which = 3)

There are periods where the volatility is relatively low and stable, suggesting less market turbulence.

ACF of Standardized Residuals

plot(portfolio_df.garcht11, which = 10)

ACF of Squared Standardized Residuals

plot(portfolio_df.garcht11, which = 11)

News-impact curve

plot(portfolio_df.garcht11, which = 12)

Positive and negative shocks of equal magnitude have the same impact on volatility. The U-shaped curve indicates that both positive and negative shocks increase volatility, but the impact diminishes as the magnitude of the shock decreases.

The EGARCH in mean-t model

Let’s first define the model specification:

spec <- ugarchspec(# variance equation
                   variance.model = list(model = "eGARCH", 
                                         garchOrder = c(1, 1)),
                   # mean equation
                   mean.model = list(armaOrder = c(0, 0), 
                                     include.mean = TRUE,
                                     archm = TRUE, archpow = 1), 
                   # assumed distribution of errors
                   distribution.model = "std") # std = t-Student

Now, we estimate the model:

portfolio_df.egarchmt11 <- ugarchfit(spec = spec, 
                             data = portfolio_df$r)

The model summary:

portfolio_df.egarchmt11
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : eGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : std 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error    t value Pr(>|t|)
## mu     -0.001916    0.001114  -1.719904 0.085450
## archm   0.218793    0.081423   2.687123 0.007207
## omega  -0.388420    0.056812  -6.836986 0.000000
## alpha1 -0.000857    0.024814  -0.034522 0.972461
## beta1   0.953938    0.006625 143.996472 0.000000
## gamma1  0.207409    0.038656   5.365490 0.000000
## shape   4.857327    0.753861   6.443268 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error    t value Pr(>|t|)
## mu     -0.001916    0.000701  -2.732208 0.006291
## archm   0.218793    0.050113   4.365977 0.000013
## omega  -0.388420    0.029135 -13.331581 0.000000
## alpha1 -0.000857    0.030138  -0.028423 0.977325
## beta1   0.953938    0.002941 324.388058 0.000000
## gamma1  0.207409    0.047268   4.387916 0.000011
## shape   4.857327    0.763383   6.362897 0.000000
## 
## LogLikelihood : 2522.855 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -5.6536
## Bayes        -5.6159
## Shibata      -5.6537
## Hannan-Quinn -5.6392
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.197  0.2740
## Lag[2*(p+q)+(p+q)-1][2]     1.820  0.2945
## Lag[4*(p+q)+(p+q)-1][5]     2.748  0.4551
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                   0.004974 0.94377
## Lag[2*(p+q)+(p+q)-1][5]  5.869845 0.09651
## Lag[4*(p+q)+(p+q)-1][9]  7.008826 0.19842
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]    0.1570 0.500 2.000  0.6920
## ARCH Lag[5]    0.6140 1.440 1.667  0.8495
## ARCH Lag[7]    0.7192 2.315 1.543  0.9545
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  1.3704
## Individual Statistics:             
## mu     0.4842
## archm  0.4970
## omega  0.1803
## alpha1 0.1417
## beta1  0.1916
## gamma1 0.1379
## shape  0.2291
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.69 1.9 2.35
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           0.9857 0.3246    
## Negative Sign Bias  0.4686 0.6395    
## Positive Sign Bias  0.7294 0.4660    
## Joint Effect        1.9941 0.5736    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     15.93       0.6618
## 2    30     30.63       0.3831
## 3    40     37.55       0.5360
## 4    50     61.57       0.1072
## 
## 
## Elapsed time : 0.1682701

Interpration

1.Ljung-Box Tests for Residuals and Squared Residuals: There is no significant serial correlation present in the residuals or their squares based on these tests.

2.Arch Test for Residuals: There is not enough evidence to reject the null hypothesis of no conditional heteroskedasticity at any of the tested lag lengths. Therefore, based on these results, the data do not exhibit significant conditional heteroskedasticity.

3.Nyblom Stability Test: There is no evidence to suggest parameter instability in your model.

4.Sign Bias Test: there’s no significant evidence to suggest a systematic bias in the predictions of your model.

5.Adjusted Pearson Goodness-of-Fit Test: There’s no strong evidence to suggest significant deviations between the observed data and the specified theoretical distribution for most groups.

Conditional SD (vs |returns|)

plot(portfolio_df.garcht11, which = 3)

There are periods where the volatility is relatively low and stable, suggesting less market turbulence.

ACF of Standardized Residuals

plot(portfolio_df.garcht11, which = 10)

ACF of Squared Standardized Residuals

plot(portfolio_df.garcht11, which = 11)

News-impact curve

plot(portfolio_df.garcht11, which = 12)

Positive and negative shocks of equal magnitude have the same impact on volatility. The U-shaped curve indicates that both positive and negative shocks increase volatility, but the impact diminishes as the magnitude of the shock decreases.

Now, let’s compare information criteria for all models:

compare_ICs_ugarchfit(c("portfolio_df.garch11",
                        "portfolio_df.egarch11",
                        "portfolio_df.garchm11", 
                        "portfolio_df.garcht11", 
                        "portfolio_df.egarchmt11"))
## $ICs
##      Akaike     Bayes   Shibata Hannan.Quinn                   model
## 1 -5.549567 -5.528033 -5.549607    -5.541336    portfolio_df.garch11
## 2 -5.547386 -5.520469 -5.547449    -5.537098   portfolio_df.egarch11
## 3 -5.549036 -5.522119 -5.549099    -5.538748   portfolio_df.garchm11
## 4 -5.656951 -5.630034 -5.657014    -5.646663   portfolio_df.garcht11
## 5 -5.653606 -5.615923 -5.653729    -5.639203 portfolio_df.egarchmt11
## 
## $which.min
##       Akaike        Bayes      Shibata Hannan.Quinn 
##            4            4            4            4

Calculation of VaR

VaR in the IN-SAMPLE period for the GARCH-t model

Standardization of returns.

portfolio_df$rstd <- (portfolio_df$r - mean(portfolio_df$r, na.rm = T)) /
    sd(portfolio_df$r ,na.rm = T)
tail(portfolio_df)
##           date            r        stan        rstd
## 885 2022-12-22 -0.013659920 -0.86859005 -0.86859005
## 886 2022-12-23  0.002053295  0.06072186  0.06072186
## 887 2022-12-27  0.003362720  0.13816399  0.13816399
## 888 2022-12-28 -0.011738050 -0.75492673 -0.75492673
## 889 2022-12-29  0.015381272  0.84896594  0.84896594
## 890 2022-12-30 -0.006366028 -0.43721426 -0.43721426

1% empirical quantile

q01 <- quantile(portfolio_df$rstd, 0.01, na.rm = T)
q01
##        1% 
## -2.631463

For comparison: 1% quantile of standard normal distribution

qnorm(0.01, 0, 1)
## [1] -2.326348
str(portfolio_df.garcht11)
## Formal class 'uGARCHfit' [package "rugarch"] with 2 slots
##   ..@ fit  :List of 27
##   .. ..$ hessian        : num [1:5, 1:5] 5736246 5827313 3135 1829 119 ...
##   .. ..$ cvar           : num [1:5, 1:5] 1.75e-07 -6.59e-12 -4.52e-08 1.57e-07 -1.04e-05 ...
##   .. ..$ var            : num [1:890] 0.000286 0.00034 0.000327 0.000292 0.000273 ...
##   .. ..$ sigma          : num [1:890] 0.0169 0.0184 0.0181 0.0171 0.0165 ...
##   .. ..$ condH          : num NaN
##   .. ..$ z              : num [1:890] -1.7753 0.8619 -0.0386 0.6134 0.1901 ...
##   .. ..$ LLH            : num 2522
##   .. ..$ log.likelihoods: num [1:890] -1.2 -2.61 -3.3 -3 -3.36 ...
##   .. ..$ residuals      : num [1:890] -0.03 0.015899 -0.000698 0.010489 0.003142 ...
##   .. ..$ coef           : Named num [1:5] 1.06e-03 1.39e-05 9.24e-02 8.52e-01 4.89
##   .. .. ..- attr(*, "names")= chr [1:5] "mu" "omega" "alpha1" "beta1" ...
##   .. ..$ robust.cvar    : num [1:5, 1:5] 1.58e-07 6.93e-11 -3.95e-07 -2.04e-07 -3.16e-06 ...
##   .. ..$ A              : num [1:5, 1:5] 6445.22 6547.543 3.523 2.055 0.134 ...
##   .. ..$ B              : num [1:5, 1:5] 5.84e+03 -8.27e+04 2.91 -5.50 -8.96e-04 ...
##   .. ..$ scores         : num [1:890, 1:5] 102.16 -77.48 7.14 -63.8 -24.03 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:5] "mu" "omega" "alpha1" "beta1" ...
##   .. ..$ se.coef        : num [1:5] 4.18e-04 1.76e-06 6.56e-04 1.97e-02 6.87e-01
##   .. ..$ tval           : Named num [1:5] 2.54 7.9 140.79 43.32 7.11
##   .. .. ..- attr(*, "names")= chr [1:5] "mu" "omega" "alpha1" "beta1" ...
##   .. ..$ matcoef        : num [1:5, 1:4] 1.06e-03 1.39e-05 9.24e-02 8.52e-01 4.89 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:5] "mu" "omega" "alpha1" "beta1" ...
##   .. .. .. ..$ : chr [1:4] " Estimate" " Std. Error" " t value" "Pr(>|t|)"
##   .. ..$ robust.se.coef : num [1:5] 3.98e-04 2.72e-06 1.40e-02 1.53e-02 6.00e-01
##   .. ..$ robust.tval    : Named num [1:5] 2.67 5.09 6.62 55.5 8.14
##   .. .. ..- attr(*, "names")= chr [1:5] "mu" "omega" "alpha1" "beta1" ...
##   .. ..$ robust.matcoef : num [1:5, 1:4] 1.06e-03 1.39e-05 9.24e-02 8.52e-01 4.89 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:5] "mu" "omega" "alpha1" "beta1" ...
##   .. .. .. ..$ : chr [1:4] " Estimate" " Std. Error" " t value" "Pr(>|t|)"
##   .. ..$ fitted.values  : num [1:890] 0.00106 0.00106 0.00106 0.00106 0.00106 ...
##   .. ..$ convergence    : num 0
##   .. ..$ kappa          : num 1
##   .. ..$ persistence    : num 0.944
##   .. ..$ timer          : 'difftime' num 0.0621180534362793
##   .. .. ..- attr(*, "units")= chr "secs"
##   .. ..$ ipars          : num [1:19, 1:6] 0.00106 0 0 0 0 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:19] "mu" "ar" "ma" "arfima" ...
##   .. .. .. ..$ : chr [1:6] "Level" "Fixed" "Include" "Estimate" ...
##   .. ..$ solver         :List of 2
##   .. .. ..$ sol :List of 10
##   .. .. .. ..$ pars       : Named num [1:5] 1.06e-03 1.39e-05 9.24e-02 8.52e-01 4.89
##   .. .. .. .. ..- attr(*, "names")= chr [1:5] "mu" "omega" "alpha1" "beta1" ...
##   .. .. .. ..$ convergence: num 0
##   .. .. .. ..$ values     : num [1:3] -2395 -2522 -2522
##   .. .. .. ..$ lagrange   : num [1, 1] 0.000247
##   .. .. .. ..$ hessian    : num [1:6, 1:6] 0.337 10.671 7498.048 -0.862 -1.437 ...
##   .. .. .. ..$ ineqx0     : Named num 0.944
##   .. .. .. .. ..- attr(*, "names")= chr ""
##   .. .. .. ..$ nfuneval   : num 261
##   .. .. .. ..$ outer.iter : num 2
##   .. .. .. ..$ elapsed    : 'difftime' num 0.0615501403808594
##   .. .. .. .. ..- attr(*, "units")= chr "secs"
##   .. .. .. ..$ vscale     : num [1:7] 1 1 1 1 1 1 1
##   .. .. ..$ hess: NULL
##   ..@ model:List of 11
##   .. ..$ modelinc  : Named num [1:22] 1 0 0 0 0 0 1 1 1 0 ...
##   .. .. ..- attr(*, "names")= chr [1:22] "mu" "ar" "ma" "arfima" ...
##   .. ..$ modeldesc :List of 3
##   .. .. ..$ distribution: chr "std"
##   .. .. ..$ distno      : int 3
##   .. .. ..$ vmodel      : chr "sGARCH"
##   .. ..$ modeldata :List of 4
##   .. .. ..$ T     : int 890
##   .. .. ..$ data  : num [1:890] -0.028939 0.01696 0.000363 0.01155 0.004203 ...
##   .. .. ..$ index : POSIXct[1:890], format: "1970-01-02" ...
##   .. .. ..$ period: 'difftime' num 1
##   .. .. .. ..- attr(*, "units")= chr "days"
##   .. ..$ pars      : num [1:19, 1:6] 0.00106 0 0 0 0 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:19] "mu" "ar" "ma" "arfima" ...
##   .. .. .. ..$ : chr [1:6] "Level" "Fixed" "Include" "Estimate" ...
##   .. ..$ start.pars: NULL
##   .. ..$ fixed.pars: NULL
##   .. ..$ maxOrder  : num 1
##   .. ..$ pos.matrix: num [1:21, 1:3] 1 0 0 0 0 0 2 3 4 0 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:21] "mu" "ar" "ma" "arfima" ...
##   .. .. .. ..$ : chr [1:3] "start" "stop" "include"
##   .. ..$ fmodel    : NULL
##   .. ..$ pidx      : num [1:19, 1:2] 1 2 3 4 5 6 7 8 9 10 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:19] "mu" "ar" "ma" "arfima" ...
##   .. .. .. ..$ : chr [1:2] "begin" "end"
##   .. ..$ n.start   : num 0
head(portfolio_df.garcht11@fit$sigma)
## [1] 0.01689897 0.01844567 0.01808292 0.01709957 0.01652433 0.01572661

Calculating value-at-risk (VaR) the GARCH-t model.

portfolio_df$var <- q01*portfolio_df.garcht11@fit$sigma
tail(portfolio_df)
##           date            r        stan        rstd         var
## 885 2022-12-22 -0.013659920 -0.86859005 -0.86859005 -0.04057937
## 886 2022-12-23  0.002053295  0.06072186  0.06072186 -0.04046103
## 887 2022-12-27  0.003362720  0.13816399  0.13816399 -0.03861211
## 888 2022-12-28 -0.011738050 -0.75492673 -0.75492673 -0.03700195
## 889 2022-12-29  0.015381272  0.84896594  0.84896594 -0.03697144
## 890 2022-12-30 -0.006366028 -0.43721426 -0.43721426 -0.03730095

Plot of returns vs value-at-risk.

plot(portfolio_df$date,portfolio_df$r,  col="red", 
     lwd=1,type="l", ylim= c(-0.1, 0.1))
abline(h = 0, lty = 2)
lines(portfolio_df$date,portfolio_df$var,col="green", type="l")

In how many days losses were higher than the assumed value-at-risk?

sum(portfolio_df$r < portfolio_df$var)/ length(portfolio_df$var)
## [1] 0.01348315

VaR in the OUT-OF-SAMPLE period fot the GARCH-t model

Plot of conditional standard deviation and its on-day ahead prediction.

plot(ugarchforecast(portfolio_df.garcht11, na.ahead=1), which=3)

Plot of conditional standard deviation forecasts in the long run.

plot(ugarchforecast(portfolio_df.garcht11, n.ahead = 200), which=3)

We can combine them with the in-sample estimation of conditional standard deviation

sigma.forecast.longrun <- ugarchforecast(portfolio_df.garcht11, n.ahead = 500)
unconditional_sigma <- 
  sqrt(
    portfolio_df.garch11@model$pars["omega", 1] / 
      (1 - 
         portfolio_df.garcht11@model$pars["alpha1", 1] -
         portfolio_df.garcht11@model$pars["beta1", 1]))
plot(
  c(as.numeric(portfolio_df.garcht11@fit$sigma),
    as.numeric(sigma.forecast.longrun@forecast$sigmaFor)),
  type = "l",
  ylab = "sigma")
abline(h = unconditional_sigma, col = "red")

Yet a better idea is to annualize all of these values.

plot(
  c(as.numeric(portfolio_df.garcht11@fit$sigma * sqrt(252)),
    as.numeric(sigma.forecast.longrun@forecast$sigmaFor * sqrt(252))),
  type = "l",
  ylab = "sigma annualized")
abline(h = unconditional_sigma * sqrt(252), col = "red")

Now, the loop below calculates predictions of VaR for the whole OUT-OF-SAMPLE period

portfolio_df1 <-
  portfolio_df1 %>%
  mutate(obs = row_number())
start   <- portfolio_df1$obs[portfolio_df1$date == as.Date("2023-01-03")]
finish  <- portfolio_df1$obs[portfolio_df1$date == as.Date("2024-05-30")]
portfolio_df2 <- portfolio_df1[start:finish, ]
VaR <- rep(NA, times = finish - start + 1)
mu     <- rep(NA, times = finish - start + 1)
omega  <- rep(NA, times = finish - start + 1)
alpha1 <- rep(NA, times = finish - start + 1)
beta1  <- rep(NA, times = finish - start + 1)

Calculation lasts for ~90-120 seconds:

time1 <- Sys.time()
for (k in start:finish) {
    tmp.data <- portfolio_df1[portfolio_df1$obs <= (k - 1), ]
    tmp.data <- tmp.data[as.Date("2019-01-01") <= tmp.data$date, ]
    tmp.data$rstd <- 
      (tmp.data$r - mean(tmp.data$r, na.rm = T)) / sd(tmp.data$r, na.rm = T)
    q01  <- quantile(tmp.data$rstd, 0.01, na.rm = T)
    spec <- 
      ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),
                 mean.model     = list(armaOrder = c(0, 0), include.mean = T),
                 distribution.model = "std")
    tmp.garch11           <- ugarchfit(spec = spec, data = na.omit(tmp.data$r))
    sigma.forecast        <- ugarchforecast(tmp.garch11, n.ahead = 1)
    sigma.forecast2       <- sigma.forecast@forecast$sigmaFor[1, 1]
    VaR[k - start + 1]    <- q01 * sigma.forecast2
    mu[k - start + 1]     <- tmp.garch11@fit$coef[1]
    omega[k - start + 1]  <- tmp.garch11@fit$coef[2]
    alpha1[k - start + 1] <- tmp.garch11@fit$coef[3]
    beta1[k - start + 1]  <- tmp.garch11@fit$coef[4]
  }
time2 <- Sys.time()
time2 - time1
## Time difference of 31.10518 secs

Adding VaR values to the data.frame objects.

portfolio_df2$Var <- VaR 
head(portfolio_df2$Var)
## [1] -0.03628062 -0.03488198 -0.03506423 -0.03469775 -0.03537544 -0.03432390

Plot of returns vs. VaR in the OUT-OF-SAMPLE period

plot(portfolio_df2$date, portfolio_df2$r, col = "red", lwd = 1, type = 'l',
     ylim = c(-0.20, 0.20))
abline(h = 0, lty = 2)
lines(portfolio_df2$date, portfolio_df2$Var, type = 'l', col = "green")

In how many days losses were higher than the assumed VaR?

sum(portfolio_df2$r < portfolio_df2$Var) / length(portfolio_df2$Var)
## [1] 0

VaR in the IN-SAMPLE period for the GARCH-mean-t model

str(portfolio_df.egarchmt11)
## Formal class 'uGARCHfit' [package "rugarch"] with 2 slots
##   ..@ fit  :List of 27
##   .. ..$ hessian        : num [1:7, 1:7] 5860725 87395 84383 -20633 -620726 ...
##   .. ..$ cvar           : num [1:7, 1:7] -1.24e-06 9.80e-05 -1.73e-05 1.01e-07 -1.89e-06 ...
##   .. ..$ var            : num [1:890] 0.000294 0.000362 0.000357 0.000306 0.00029 ...
##   .. ..$ sigma          : num [1:890] 0.0172 0.019 0.0189 0.0175 0.017 ...
##   .. ..$ condH          : num NaN
##   .. ..$ z              : num [1:890] -1.7942 0.773 -0.0981 0.5515 0.1407 ...
##   .. ..$ LLH            : num 2523
##   .. ..$ log.likelihoods: num [1:890] -1.15 -2.7 -3.25 -3.05 -3.35 ...
##   .. ..$ residuals      : num [1:890] -0.03078 0.01471 -0.00185 0.00964 0.0024 ...
##   .. ..$ coef           : Named num [1:7] -0.001916 0.218793 -0.38842 -0.000857 0.953938 ...
##   .. .. ..- attr(*, "names")= chr [1:7] "mu" "archm" "omega" "alpha1" ...
##   .. ..$ robust.cvar    : num [1:7, 1:7] 4.92e-07 -2.75e-05 -8.16e-07 1.70e-06 6.86e-09 ...
##   .. ..$ A              : num [1:7, 1:7] 6585.1 98.2 94.8 -23.2 -697.4 ...
##   .. ..$ B              : num [1:7, 1:7] 5820 79.3 56.2 15.4 -458.5 ...
##   .. ..$ scores         : num [1:890, 1:7] 118.07 -68.31 3.46 -58.71 -23.1 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:7] "mu" "archm" "omega" "alpha1" ...
##   .. ..$ se.coef        : num [1:7] 0.00111 0.08142 0.05681 0.02481 0.00662 ...
##   .. ..$ tval           : Named num [1:7] -1.7199 2.6871 -6.837 -0.0345 143.9965 ...
##   .. .. ..- attr(*, "names")= chr [1:7] "mu" "archm" "omega" "alpha1" ...
##   .. ..$ matcoef        : num [1:7, 1:4] -0.001916 0.218793 -0.38842 -0.000857 0.953938 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:7] "mu" "archm" "omega" "alpha1" ...
##   .. .. .. ..$ : chr [1:4] " Estimate" " Std. Error" " t value" "Pr(>|t|)"
##   .. ..$ robust.se.coef : num [1:7] 0.000701 0.050113 0.029135 0.030138 0.002941 ...
##   .. ..$ robust.tval    : Named num [1:7] -2.7322 4.366 -13.3316 -0.0284 324.3881 ...
##   .. .. ..- attr(*, "names")= chr [1:7] "mu" "archm" "omega" "alpha1" ...
##   .. ..$ robust.matcoef : num [1:7, 1:4] -0.001916 0.218793 -0.38842 -0.000857 0.953938 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:7] "mu" "archm" "omega" "alpha1" ...
##   .. .. .. ..$ : chr [1:4] " Estimate" " Std. Error" " t value" "Pr(>|t|)"
##   .. ..$ fitted.values  : num [1:890] 0.00184 0.00225 0.00222 0.00191 0.00181 ...
##   .. ..$ convergence    : num 0
##   .. ..$ kappa          : num 0.732
##   .. ..$ persistence    : num 0.954
##   .. ..$ timer          : 'difftime' num 0.168270111083984
##   .. .. ..- attr(*, "units")= chr "secs"
##   .. ..$ ipars          : num [1:19, 1:6] -0.00192 0 0 0 0.21879 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:19] "mu" "ar" "ma" "arfima" ...
##   .. .. .. ..$ : chr [1:6] "Level" "Fixed" "Include" "Estimate" ...
##   .. ..$ solver         :List of 2
##   .. .. ..$ sol :List of 10
##   .. .. .. ..$ pars       : Named num [1:7] -0.001916 0.218793 -0.38842 -0.000857 0.953938 ...
##   .. .. .. .. ..- attr(*, "names")= chr [1:7] "mu" "archm" "omega" "alpha1" ...
##   .. .. .. ..$ convergence: num 0
##   .. .. .. ..$ values     : num [1:3] 294 -2523 -2523
##   .. .. .. ..$ lagrange   : num [1, 1] 2.8e-05
##   .. .. .. ..$ hessian    : num [1:8, 1:8] 0.405 7.943 0.285 2.192 0.494 ...
##   .. .. .. ..$ ineqx0     : Named num 1.05
##   .. .. .. .. ..- attr(*, "names")= chr ""
##   .. .. .. ..$ nfuneval   : num 224
##   .. .. .. ..$ outer.iter : num 2
##   .. .. .. ..$ elapsed    : 'difftime' num 0.0862560272216797
##   .. .. .. .. ..- attr(*, "units")= chr "secs"
##   .. .. .. ..$ vscale     : num [1:9] 1 1 1 1 1 1 1 1 1
##   .. .. ..$ hess: NULL
##   ..@ model:List of 11
##   .. ..$ modelinc  : Named num [1:22] 1 0 0 0 1 0 1 1 1 1 ...
##   .. .. ..- attr(*, "names")= chr [1:22] "mu" "ar" "ma" "arfima" ...
##   .. ..$ modeldesc :List of 3
##   .. .. ..$ distribution: chr "std"
##   .. .. ..$ distno      : int 3
##   .. .. ..$ vmodel      : chr "eGARCH"
##   .. ..$ modeldata :List of 4
##   .. .. ..$ T     : int 890
##   .. .. ..$ data  : num [1:890] -0.028939 0.01696 0.000363 0.01155 0.004203 ...
##   .. .. ..$ index : POSIXct[1:890], format: "1970-01-02" ...
##   .. .. ..$ period: 'difftime' num 1
##   .. .. .. ..- attr(*, "units")= chr "days"
##   .. ..$ pars      : num [1:19, 1:6] -0.00192 0 0 0 0.21879 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:19] "mu" "ar" "ma" "arfima" ...
##   .. .. .. ..$ : chr [1:6] "Level" "Fixed" "Include" "Estimate" ...
##   .. ..$ start.pars: NULL
##   .. ..$ fixed.pars: NULL
##   .. ..$ maxOrder  : num 1
##   .. ..$ pos.matrix: num [1:21, 1:3] 1 0 0 0 2 0 3 4 5 6 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:21] "mu" "ar" "ma" "arfima" ...
##   .. .. .. ..$ : chr [1:3] "start" "stop" "include"
##   .. ..$ fmodel    : NULL
##   .. ..$ pidx      : num [1:19, 1:2] 1 2 3 4 5 6 7 8 9 10 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:19] "mu" "ar" "ma" "arfima" ...
##   .. .. .. ..$ : chr [1:2] "begin" "end"
##   .. ..$ n.start   : num 0
head(portfolio_df.egarchmt11@fit$sigma)
## [1] 0.01715327 0.01903247 0.01888400 0.01748296 0.01702073 0.01590208

Calculating value-at-risk (VaR) the GARCH-mean-t model.

portfolio_df$varmt <- q01*portfolio_df.egarchmt11@fit$sigma
tail(portfolio_df)
##           date            r        stan        rstd         var       varmt
## 885 2022-12-22 -0.013659920 -0.86859005 -0.86859005 -0.04057937 -0.04109564
## 886 2022-12-23  0.002053295  0.06072186  0.06072186 -0.04046103 -0.04207721
## 887 2022-12-27  0.003362720  0.13816399  0.13816399 -0.03861211 -0.03899856
## 888 2022-12-28 -0.011738050 -0.75492673 -0.75492673 -0.03700195 -0.03668207
## 889 2022-12-29  0.015381272  0.84896594  0.84896594 -0.03697144 -0.03756782
## 890 2022-12-30 -0.006366028 -0.43721426 -0.43721426 -0.03730095 -0.03869597

Plot of returns vs value-at-risk.

plot(portfolio_df$date,portfolio_df$r,  col="red", 
     lwd=1,type="l", ylim= c(-0.1, 0.1))
abline(h = 0, lty = 2)
lines(portfolio_df$date,portfolio_df$varmt,col="green", type="l")

In how many days losses were higher than the assumed value-at-risk?

sum(portfolio_df$r < portfolio_df$varmt)/ length(portfolio_df$varmt)
## [1] 0.01348315

VaR in the OUT-OF-SAMPLE period for the GARCH-mean-t model

Plot of conditional standard deviation and its on-day ahead prediction.

plot(ugarchforecast(portfolio_df.egarchmt11, na.ahead=1), which=3)

Plot of conditional standard deviation forecasts in the long run.

plot(ugarchforecast(portfolio_df.egarchmt11, n.ahead = 200), which=3)

We can combine them with the in-sample estimation of conditional standard deviation

sigma.forecast.longrun <- ugarchforecast(portfolio_df.egarchmt11, n.ahead = 500)
unconditional_sigma <- 
  sqrt(
    portfolio_df.egarchmt11@model$pars["omega", 1] / 
      (1 - 
         portfolio_df.egarchmt11@model$pars["alpha1", 1] -
         portfolio_df.egarchmt11@model$pars["beta1", 1]))
## Warning in sqrt(portfolio_df.egarchmt11@model$pars["omega", 1]/(1 -
## portfolio_df.egarchmt11@model$pars["alpha1", : NaNs produced
plot(
  c(as.numeric(portfolio_df.egarchmt11@fit$sigma),
    as.numeric(sigma.forecast.longrun@forecast$sigmaFor)),
  type = "l",
  ylab = "sigma")
abline(h = unconditional_sigma, col = "red")

Yet a better idea is to annualize all of these values.

plot(
  c(as.numeric(portfolio_df.egarchmt11@fit$sigma * sqrt(252)),
    as.numeric(sigma.forecast.longrun@forecast$sigmaFor * sqrt(252))),
  type = "l",
  ylab = "sigma annualized")
abline(h = unconditional_sigma * sqrt(252), col = "red")

Now, the loop below calculates predictions of VaR for the whole OUT-OF-SAMPLE period

portfolio_df1 <-
  portfolio_df1 %>%
  mutate(obs = row_number())
start   <- portfolio_df1$obs[portfolio_df1$date == as.Date("2023-01-03")]
finish  <- portfolio_df1$obs[portfolio_df1$date == as.Date("2024-05-30")]
portfolio_df2 <- portfolio_df1[start:finish, ]
VaR <- rep(NA, times = finish - start + 1)
mu     <- rep(NA, times = finish - start + 1)
omega  <- rep(NA, times = finish - start + 1)
alpha1 <- rep(NA, times = finish - start + 1)
beta1  <- rep(NA, times = finish - start + 1)

Calculation lasts for ~90-120 seconds:

time1 <- Sys.time()
for (k in start:finish) {
    tmp.data <- portfolio_df1[portfolio_df1$obs <= (k - 1), ]
    tmp.data <- tmp.data[as.Date("2019-01-01") <= tmp.data$date, ]
    tmp.data$rstd <- 
      (tmp.data$r - mean(tmp.data$r, na.rm = T)) / sd(tmp.data$r, na.rm = T)
    q01  <- quantile(tmp.data$rstd, 0.01, na.rm = T)
    spec <- 
      ugarchspec(variance.model = list(model = "eGARCH", garchOrder = c(1, 1)),
                 mean.model     = list(armaOrder = c(0, 0), include.mean = T),
                 distribution.model = "std")
    tmp.garch11           <- ugarchfit(spec = spec, data = na.omit(tmp.data$r))
    sigma.forecast        <- ugarchforecast(tmp.garch11, n.ahead = 1)
    sigma.forecast2       <- sigma.forecast@forecast$sigmaFor[1, 1]
    VaR[k - start + 1]    <- q01 * sigma.forecast2
    mu[k - start + 1]     <- tmp.garch11@fit$coef[1]
    omega[k - start + 1]  <- tmp.garch11@fit$coef[2]
    alpha1[k - start + 1] <- tmp.garch11@fit$coef[3]
    beta1[k - start + 1]  <- tmp.garch11@fit$coef[4]
  }
time2 <- Sys.time()
time2 - time1
## Time difference of 54.66239 secs

Adding VaR values to the data.frame objects.

portfolio_df2$Var <- VaR
head(portfolio_df2$Var)
## [1] -0.03771902 -0.03527382 -0.03613666 -0.03618297 -0.03748307 -0.03609196

Plot of returns vs. VaR in the OUT-OF-SAMPLE period

plot(portfolio_df2$date, portfolio_df2$r, col = "red", lwd = 1, type = 'l',
     ylim = c(-0.20, 0.20))
abline(h = 0, lty = 2)
lines(portfolio_df2$date, portfolio_df2$Var, type = 'l', col = "green")

In how many days losses were higher than the assumed VaR?

sum(portfolio_df2$r < portfolio_df2$Var) / length(portfolio_df2$Var)
## [1] 0